package com.ruyixing.shopmanager.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.text.format.DateFormat;

public class TimeUtils {

	public static final String DEFAULT_DATE_FORMATER = "yyyy年MM月dd日";
	public static final String EE_DATE_FORMATER = "yyyy-MM-dd EE";
	public static final String DEFAULT_TIME_FORMATER = "hh:mm";

	public static final CharSequence getEEDayString(Calendar c) {
		return DateFormat.format(EE_DATE_FORMATER, c);
	}

	public static final CharSequence getTimeString(Calendar c) {
		return DateFormat.format(DEFAULT_TIME_FORMATER, c);
	}

	public static final CharSequence getTodayString() {
		return DateFormat.format(DEFAULT_DATE_FORMATER, Calendar.getInstance());
	}

	public static final CharSequence getDayString(Calendar c) {
		return DateFormat.format(DEFAULT_DATE_FORMATER, c);
	}

	public static final CharSequence getDayString(Calendar c, int dayGap) {
		c.add(Calendar.DAY_OF_MONTH, dayGap);
		return DateFormat.format(DEFAULT_DATE_FORMATER, c);
	}

	public static final Calendar parsrDate(String dateString) {
		SimpleDateFormat format = new SimpleDateFormat(DEFAULT_DATE_FORMATER);
		Calendar c = Calendar.getInstance();

		try {
			Date date = format.parse(dateString);
			c.setTime(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return c;
	}

	public static final Calendar parsrEEDate(String dateString) {
		SimpleDateFormat format = new SimpleDateFormat(EE_DATE_FORMATER);
		Calendar c = Calendar.getInstance();

		try {
			Date date = format.parse(dateString);
			c.setTime(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return c;
	}

	public static final Calendar parsrTime(String dateString) {
		SimpleDateFormat format = new SimpleDateFormat(DEFAULT_TIME_FORMATER);
		Calendar c = Calendar.getInstance();

		try {
			Date date = format.parse(dateString);
			c.setTime(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return c;
	}

	public static final Calendar getCalendar(int year, int monthOfYear,
			int dayOfMonth) {
		Calendar c = Calendar.getInstance();

		c.set(Calendar.YEAR, year);
		c.set(Calendar.MONTH, monthOfYear);
		c.set(Calendar.DAY_OF_MONTH, dayOfMonth);

		return c;
	}

	public static final Calendar getCalendar(int hourOfDay, int minute) {
		Calendar c = Calendar.getInstance();

		c.set(Calendar.HOUR_OF_DAY, hourOfDay);
		c.set(Calendar.MINUTE, minute);

		return c;
	}
}
